<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>为该连接设置读取选项</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="mongoclient.selectdb.html">MongoClient::selectDB</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="mongoclient.tostring.html">MongoClient::__toString</a></div>
 <div class="up"><a href="class.mongoclient.html">MongoClient</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="mongoclient.setreadpreference" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">MongoClient::setReadPreference</h1>
  <p class="verinfo">(PECL mongo &gt;=1.3.0)</p><p class="refpurpose"><span class="refname">MongoClient::setReadPreference</span> &mdash; <span class="dc-title">为该连接设置读取选项</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-mongoclient.setreadpreference-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">bool</span> <span class="methodname"><strong>MongoClient::setReadPreference</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$read_preference</code></span>
   [, <span class="methodparam"><span class="type">array</span> <code class="parameter">$tags</code></span>
  ] )</div>

 </div>


 <div class="refsect1 parameters" id="refsect1-mongoclient.setreadpreference-parameters">
  <h3 class="title">参数</h3>
  <dl>
<dt>
<em><code class="parameter">read_preference</code></em></dt>
<dd>
<p class="para">The read preference mode: <strong><code>MongoClient::RP_PRIMARY</code></strong>, <strong><code>MongoClient::RP_PRIMARY_PREFERRED</code></strong>, <strong><code>MongoClient::RP_SECONDARY</code></strong>, <strong><code>MongoClient::RP_SECONDARY_PREFERRED</code></strong>, or <strong><code>MongoClient::RP_NEAREST</code></strong>.</p></dd>
<dt>
<em><code class="parameter">tags</code></em></dt>
<dd>
<p class="para">An array of zero or more tag sets, where each tag set is itself an array of criteria used to match tags on replica set members.</p></dd>
</dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-mongoclient.setreadpreference-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">Returns <strong><code>TRUE</code></strong> on success, or <strong><code>FALSE</code></strong> otherwise.</p>
 </div>


 <div class="refsect1 errors" id="refsect1-mongoclient.setreadpreference-errors">
  <h3 class="title">错误／异常</h3>
  <p class="para">Emits <strong><code>E_WARNING</code></strong> if either parameter is invalid, or if one or more tag sets are provided with the <strong><code>MongoClient::RP_PRIMARY</code></strong> read preference mode.</p>
 </div>


 <div class="refsect1 examples" id="refsect1-mongoclient.setreadpreference-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-1378">
   <p><strong>Example #1 <span class="methodname"><strong>MongoClient::setReadPreference()</strong></span> 标签集数组语法的例子</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$m&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">MongoClient</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">//&nbsp;首选最近的&nbsp;"east"&nbsp;数据中心的服务器，也用于报告，<br />//&nbsp;失败时调用&nbsp;"west"&nbsp;数据中心的服务器<br /></span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setReadPreference</span><span style="color: #007700">(</span><span style="color: #0000BB">MongoClient</span><span style="color: #007700">::</span><span style="color: #0000BB">RP_NEAREST</span><span style="color: #007700">,&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;array(</span><span style="color: #DD0000">'dc'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'east'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'use'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'reporting'</span><span style="color: #007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;array(</span><span style="color: #DD0000">'dc'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'west'</span><span style="color: #007700">),<br />));</span>
</span>
</code></div>
   </div>

  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-mongoclient.setreadpreference-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li class="member"><a href="mongo.readpreferences.html" class="link">读取选修</a>的文档。</li>
  </ul>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="mongoclient.selectdb.html">MongoClient::selectDB</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="mongoclient.tostring.html">MongoClient::__toString</a></div>
 <div class="up"><a href="class.mongoclient.html">MongoClient</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
